/**
 * Created with IntelliJ IDEA.
 * Description:线程中断
 * User: 东莞呵呵
 * Date:2022-09-15
 * Time:17:28
 */
public class Demo12 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread=new Thread (){
            @Override
            public void run() {
                while (!Thread.currentThread().isInterrupted()){
                    System.out.println("run1");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        System.out.println("捕捉到异常");
                        break;
                    }
                }
                System.out.println("线程已经被中断");
            }
        };
        thread.start();
        Thread.sleep(5000);
        thread.interrupt();
    }
}
